package com.four.dailymanage.dish.dao;

import com.four.dailymanage.dish.entity.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishDao {
    /**
     * 根据菜品名称  菜品类别 发布与否  发布时间  分配时间 来进行查询
     * @param start
     * @param size
     * @param dishName
     * @param dishType
     * @param publish
     * @param publishDt
     * @param assignDt
     * @return
     */
    @Select("<script>" +
            "SELECT * FROM dish" +
            "  <where>" +
            "    <if test=\" dishName != null\">" +
            "     <bind name=\"nameKey\" value=\"'%'+dishName+'%'\"/>"+
            "       and dishName like #{nameKey} " +
            "    </if>" +
            "    <if test=\" dishType != null\">" +
            "       and dishType = #{dishType} " +
            "    </if>" +
            "    <if test=\" publish != null\">" +
            "       and publish = #{publish} " +
            "    </if>" +
            "    <if test=\" publishDt != null\">" +
            "       and publishDt = #{publishDt} " +
            "    </if>" +
            "    <if test=\" assignDt != null\">" +
            "       and assignDt = #{assignDt} " +
            "    </if>" +
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")

    public List<Dish> getDishByCon(int start, int size, String dishName,String dishType,String publish, String publishDt,
                                          String assignDt);
    @Select("<script>" +
            "SELECT count(*) FROM dish" +
            "  <where>" +
            "    <if test=\" dishName != null\">" +
            "     <bind name=\"nameKey\" value=\"'%'+dishName+'%'\"/>"+
            "       and dishName like #{nameKey} " +
            "    </if>" +
            "    <if test=\" dishType != null\">" +
            "       and dishType = #{dishType} " +
            "    </if>" +
            "    <if test=\" publish != null\">" +
            "       and publish = #{publish} " +
            "    </if>" +
            "    <if test=\" publishDt != null\">" +
            "       and publishDt = #{publishDt} " +
            "    </if>" +
            "    <if test=\" assignDt != null\">" +
            "     <bind name=\"DtKey\" value=\"'%'+assignDt+'%'\"/>"+
            "       and assignDt like #{DtKey} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public  int countDish(String dishName,String dishType,String publish, String publishDt,
                          String assignDt);

    //添加菜品
    @Insert("insert into dish(dishType,numLimit,dishName,price,discountPrice,assignDt,note,photourl)" +
            "values (#{dishType},#{numLimit},#{dishName},#{price},#{discountPrice},#{assignDt},#{note},#{photourl})")
    public int insertDish(Dish dish);

    //删除一个菜品
    @Delete("delete from dish where id=#{id}")
    public int deleteDishById(Integer id);
    //删除多个菜品
    @Delete("<script>" +
            "  delete from dish where id in" +
            "  <foreach collection=\"ids\" item=\"did\" open=\"(\" close=\")\" separator=\",\">" +
            "    #{did}" +
            "   </foreach>" +
            "</script>")
    public int deletes(List<Integer> id);
    //修改菜品
    @Update("<script>" +
            "update  dish " +
            "        <set>" +
            "            <if test=\"null!= photourl\">" +
            "                photourl =#{photourl}," +
            "            </if>" +
            "            <if test=\" numLimit > 0\">" +
            "                numLimit =#{numLimit}," +
            "            </if>" +
            "            <if test=\" discountPrice > 0\">" +
            "                discountPrice =#{discountPrice}," +
            "            </if>" +
            "            <if test=\" photourl != null \">" +
            "                photourl =#{photourl}," +
            "            </if>" +
            "            <if test=\"  note!= null\">" +
            "                note =#{note}," +
            "            </if>" +
            "            <if test=\"  publish != null\">" +
            "                publish =#{publish}," +
            "            </if>" +
            "            <if test=\" publishDt != null \">" +
            "                publishDt =#{publishDt}," +
            "            </if>" +
            "            <if test=\" assignDt != null \">" +
            "                assignDt =#{assignDt}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int update(Dish dish);
}
